﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Maticsoft.Model;
namespace Maticsoft.BLL
{
	/// <summary>
	/// Books
	/// </summary>
	public partial class Books
	{
		private readonly Maticsoft.DAL.Books dal=new Maticsoft.DAL.Books();
		public Books()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int BookId)
		{
			return dal.Exists(BookId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Maticsoft.Model.Books model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Maticsoft.Model.Books model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int BookId)
		{
			
			return dal.Delete(BookId);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string BookIdlist )
		{
			return dal.DeleteList(BookIdlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.Books GetModel(int BookId)
		{
			
			return dal.GetModel(BookId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Maticsoft.Model.Books GetModelByCache(int BookId)
		{
			
			string CacheKey = "BooksModel-" + BookId;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(BookId);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Maticsoft.Model.Books)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Maticsoft.Model.Books> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Maticsoft.Model.Books> DataTableToList(DataTable dt)
		{
			List<Maticsoft.Model.Books> modelList = new List<Maticsoft.Model.Books>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Maticsoft.Model.Books model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Maticsoft.Model.Books();
					if(dt.Rows[n]["BookId"]!=null && dt.Rows[n]["BookId"].ToString()!="")
					{
						model.BookId=int.Parse(dt.Rows[n]["BookId"].ToString());
					}
					if(dt.Rows[n]["BookName"]!=null && dt.Rows[n]["BookName"].ToString()!="")
					{
					model.BookName=dt.Rows[n]["BookName"].ToString();
					}
					if(dt.Rows[n]["CategoryId"]!=null && dt.Rows[n]["CategoryId"].ToString()!="")
					{
						model.CategoryId=int.Parse(dt.Rows[n]["CategoryId"].ToString());
					}
					if(dt.Rows[n]["author"]!=null && dt.Rows[n]["author"].ToString()!="")
					{
					model.author=dt.Rows[n]["author"].ToString();
					}
					if(dt.Rows[n]["SalePrice"]!=null && dt.Rows[n]["SalePrice"].ToString()!="")
					{
						model.SalePrice=decimal.Parse(dt.Rows[n]["SalePrice"].ToString());
					}
					if(dt.Rows[n]["MarketPrice"]!=null && dt.Rows[n]["MarketPrice"].ToString()!="")
					{
						model.MarketPrice=decimal.Parse(dt.Rows[n]["MarketPrice"].ToString());
					}
					if(dt.Rows[n]["PublicDate"]!=null && dt.Rows[n]["PublicDate"].ToString()!="")
					{
					model.PublicDate=dt.Rows[n]["PublicDate"].ToString();
					}
					if(dt.Rows[n]["Publisher"]!=null && dt.Rows[n]["Publisher"].ToString()!="")
					{
					model.Publisher=dt.Rows[n]["Publisher"].ToString();
					}
					if(dt.Rows[n]["ISBN"]!=null && dt.Rows[n]["ISBN"].ToString()!="")
					{
					model.ISBN=dt.Rows[n]["ISBN"].ToString();
					}
					if(dt.Rows[n]["Page"]!=null && dt.Rows[n]["Page"].ToString()!="")
					{
						model.Page=int.Parse(dt.Rows[n]["Page"].ToString());
					}
					if(dt.Rows[n]["BookChapter"]!=null && dt.Rows[n]["BookChapter"].ToString()!="")
					{
					model.BookChapter=dt.Rows[n]["BookChapter"].ToString();
					}
					if(dt.Rows[n]["Summary"]!=null && dt.Rows[n]["Summary"].ToString()!="")
					{
					model.Summary=dt.Rows[n]["Summary"].ToString();
					}
					if(dt.Rows[n]["Detail"]!=null && dt.Rows[n]["Detail"].ToString()!="")
					{
					model.Detail=dt.Rows[n]["Detail"].ToString();
					}
					if(dt.Rows[n]["CreateTime"]!=null && dt.Rows[n]["CreateTime"].ToString()!="")
					{
						model.CreateTime=DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
					}
					if(dt.Rows[n]["UpdateTime"]!=null && dt.Rows[n]["UpdateTime"].ToString()!="")
					{
						model.UpdateTime=DateTime.Parse(dt.Rows[n]["UpdateTime"].ToString());
					}
					if(dt.Rows[n]["IsActive"]!=null && dt.Rows[n]["IsActive"].ToString()!="")
					{
						model.IsActive=int.Parse(dt.Rows[n]["IsActive"].ToString());
					}
					if(dt.Rows[n]["OrderNo"]!=null && dt.Rows[n]["OrderNo"].ToString()!="")
					{
						model.OrderNo=int.Parse(dt.Rows[n]["OrderNo"].ToString());
					}
					if(dt.Rows[n]["IsHot"]!=null && dt.Rows[n]["IsHot"].ToString()!="")
					{
						model.IsHot=int.Parse(dt.Rows[n]["IsHot"].ToString());
					}
					if(dt.Rows[n]["IsGood"]!=null && dt.Rows[n]["IsGood"].ToString()!="")
					{
						model.IsGood=int.Parse(dt.Rows[n]["IsGood"].ToString());
					}
					if(dt.Rows[n]["IsHotSale"]!=null && dt.Rows[n]["IsHotSale"].ToString()!="")
					{
						model.IsHotSale=int.Parse(dt.Rows[n]["IsHotSale"].ToString());
					}
					if(dt.Rows[n]["SaleNum"]!=null && dt.Rows[n]["SaleNum"].ToString()!="")
					{
						model.SaleNum=int.Parse(dt.Rows[n]["SaleNum"].ToString());
					}
					if(dt.Rows[n]["CommentNum"]!=null && dt.Rows[n]["CommentNum"].ToString()!="")
					{
						model.CommentNum=int.Parse(dt.Rows[n]["CommentNum"].ToString());
					}
					if(dt.Rows[n]["Hits"]!=null && dt.Rows[n]["Hits"].ToString()!="")
					{
						model.Hits=int.Parse(dt.Rows[n]["Hits"].ToString());
					}
					if(dt.Rows[n]["PublishCount"]!=null && dt.Rows[n]["PublishCount"].ToString()!="")
					{
					model.PublishCount=dt.Rows[n]["PublishCount"].ToString();
					}
					if(dt.Rows[n]["BookSize"]!=null && dt.Rows[n]["BookSize"].ToString()!="")
					{
					model.BookSize=dt.Rows[n]["BookSize"].ToString();
					}
					if(dt.Rows[n]["Pic"]!=null && dt.Rows[n]["Pic"].ToString()!="")
					{
					model.Pic=dt.Rows[n]["Pic"].ToString();
					}
					if(dt.Rows[n]["Layout"]!=null && dt.Rows[n]["Layout"].ToString()!="")
					{
					model.Layout=dt.Rows[n]["Layout"].ToString();
					}
					if(dt.Rows[n]["IsTop"]!=null && dt.Rows[n]["IsTop"].ToString()!="")
					{
						model.IsTop=int.Parse(dt.Rows[n]["IsTop"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

